package com.blog.common.mapper.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * MybatisPlus 公共字段自动填充
 *
 * @author Valerie
 * @date 2023/2/18
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    /**
     * 插入时填充
     * @param metaObject
     * @return void
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
    }

    /**
     * 更新时自动填充
     * @param metaObject
     * @return void
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }
}
